home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctj0987.arc
/
DOWNLD.C
< prev
next >
Wrap
Text File
|
1987-07-02
|
5KB
|
198 lines
/* DOWNLD -- PC Tech Journal Laser Printer Font Download Test
*
* Version 1.0
*
* Copyright (c) 1987, Ziff Communications Company
* Program by: Rainer McCown and Bob Smith
*
* This routine downloads a font for a single character. It
* demonstrates how to construct the appropriate commands necessary
* to define a font. Even though the font defines but a single
* character, it can be generalized easily.
*/
#define STD_OUT 1
extern void sndl(char [], int),
snd (char []),
setbinary(int);
struct FONTDESC_STR
{
int C26;
char C0,
ftype;
int D0,
baseline,
cellwidth,
cellheight;
char orientation,
spacing;
int symbolset,
pitch,
height,
E0;
char F0,
style,
weight,
typeface;
};
struct FONTDESC_STR fontdesc;
struct CHARDESC_STR
{
char C4,
C0,
C14,
C1,
orientation,
D0;
int leftoff,
topoff,
charwidth,
charheight,
deltax;
};
struct CHARDESC_STR chardesc;
char *letter[] = {
"111111000111110000000000",
"000111001000011100000000",
"000111010000001100000000",
"000111100000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"000111000000001110000000",
"111111111001111111110000",
};
/******************************* SWAP *******************************/
unsigned int swap(ibyte)
unsigned int ibyte;
{
return(ibyte >> 8 | (ibyte & 0xff) << 8);
}
/******************************* MAIN *******************************/
void main()
{
unsigned int msgsiz, charw, charh;
char tmp[(50 * 50) >> 3], *p;
int ind, i, j;
/* Change STD_OUT to binary mode to avoid
converting LFs to CR,LF and to avoid
stopping on EOFs */
setbinary(STD_OUT);
/* Initialize the printer */
snd("\x1BE"); /* Reset the printer */
snd("\x1B&l0E"); /* Zero the top margin */
snd("\x1B&s1C"); /* Disable EOL wrap */
snd("\x1B9"); /* Clear margins */
snd("\x1B&l0O"); /* Portrait mode */
snd("\x1B(8`"); /* Select symbol set Roman-8 */
/* Define parameters of symbol set as
0p = Fixed space
16h = 16 cpi
8v = 8 pt
0s = upright
-3b = light
0T = line printer */
snd("\x1B(s0p16h8v0s-3b0T");
/* Define current font ID */
snd("\x1B*c10280D");
/* Define font descriptor */
fontdesc.C26 = swap(26); /* Constant 26 */
fontdesc.ftype = 1; /* 8-bit (use 0 for 7-bit font
type) */
fontdesc.baseline = swap(30); /* Character baseline within cell */
fontdesc.cellwidth = swap(41); /* Width of cell */
fontdesc.cellheight = swap(42); /* Height of cell */
fontdesc.orientation = 0; /* 0 = portrait, 1 = landscape */
fontdesc.spacing = 1; /* 0 = fixed, 1 = proportional */
fontdesc.symbolset = swap(277); /* Using 8` for Roman-8,
277 = 8*32 + 'U' - 64 */
fontdesc.pitch = swap(4*30); /* 30 dots wide in units of
quarter dots */
fontdesc.height = swap(4*50); /* 50 dots high ... */
fontdesc.style = 0; /* 0 = upright, 1 = italic */
fontdesc.weight = 0; /* -7 (light) to 7 (bold) */
fontdesc.typeface =swap(7); /* 5 = Times Roman */
snd("\x1B)s26W");
sndl((char *) &fontdesc, sizeof(fontdesc));
/* Describe the ASCII code for the letter 'n' */
snd("\x1B*c110E");
/* Define the header for the character 'n' */
chardesc.C1 = 1; /* Constant 1 */
chardesc.C4 = 4; /* Constant 4 */
chardesc.C14 = 14; /* Constant 14 */
chardesc.orientation = 0; /* 0 = portrait, 1 = landscape */
chardesc.leftoff = swap(1); /* Within character cell */
chardesc.topoff = swap(17); /* Within character cell */
chardesc.charwidth = swap(24); /* Width of character in dots */
chardesc.charheight = swap(18); /* Height of character in dots */
chardesc.deltax = swap(4*23); /* Skip 18 dots after printing
in units of quarter dots */
charw = swap(chardesc.charwidth);
charh = swap(chardesc.charheight);
msgsiz = sizeof(chardesc) /* Size of header plus data portion */
+ charw/8 * charh;
sprintf(tmp, "\x1B(s%dW", msgsiz); /* Start download of character */
snd(tmp);
sndl((char *) &chardesc, sizeof(chardesc));
/* Initialize TMP to all zeros in case we re-use it */
memset(tmp, 0, sizeof(tmp));
/* Define the bits which form the character 'n' */
for(ind = i = 0; i < charh; ind += charw, i++)
for(p = letter[i], j = 0;
j < charw;
j++)
tmp[(ind + j) >> 3] |= (*p++ - '0') << (7 - ((ind + j) & 7));
sndl(tmp, (charw * charh + 7) >> 3);
snd("\x1B*p342Y\x1B*p336X\x1B(10280Xn");
/* Eject page */
snd("\f");
} /* End MAIN */